/**
 * 
 */
package br.com.android.games.daedal;

import java.util.List;
import java.util.Map;

import android.os.Message;
import android.util.Log;
import br.com.games.daedal.DaedalTeam;
import br.com.games.daedal.ia.Ares;
import br.com.games.daedal.imp.Daedal;
import br.com.games.daedal.imp.DaedalPlayer;
import br.com.games.hefesto.Team;

/**
 * @author fernando
 * 
 */
public class AndroDaedal extends Daedal {

	private DaedalDotsActivity board;

	public AndroDaedal(DaedalDotsActivity board, Ares  ... players) {
		super(board.getBoard().getBoard(), players);
		this.board = board;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.hefesto.Game#help()
	 */
	@Override
	public void help() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.hefesto.Game#pause()
	 */
	@Override
	public void pause() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.hefesto.Game#exit()
	 */
	@Override
	public void exit() {
		Log.d("daedal", "daedal thread exit");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.hefesto.Game#isRunning()
	 */
	@Override
	public boolean isRunning() {
		return !board.isFinishing();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.imp.Daedal#showWinner(java.util.List,
	 * java.util.Map)
	 */
	@Override
	public void showWinner(List<? super DaedalPlayer> player,
			Map<Team, Integer> points) {		
		Message msg =  new Message();	
		Integer tm1 = points.get(DaedalTeam.WHITE);
		Integer tm2 = points.get(DaedalTeam.BLACK);
		msg.what    = DaedalDotsActivity.REQUEST_WIN_MSG;
		msg.obj     = player.get(0);
		msg.arg1    = tm1 == null ? 0 : tm1;
		msg.arg2    = tm2 == null ? 0 : tm2;
		board.update.sendMessage(msg);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * br.com.games.daedal.imp.Daedal#startNewGame(br.com.games.daedal.imp.Daedal
	 * )
	 */
	@Override
	public void startNewGame(Daedal daedal) {
		while (!board.isStartNewGame() && !board.isFinishing()) {
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		if (!board.isFinishing()) {
			board.setStartNewGame(false);
			board.update.sendEmptyMessage(DaedalDotsActivity.START_NEW_GAME);
		}
	}
}
